/*
 * Copyright (C) 2018 yixun All Rights Reserved.
 * 
 * ReportExternalServiceImpl.java
 */
package com.yixun.qfbao.service.impl;

import com.yixun.common.page.Page;
import com.yixun.qfbao.mapper.ReportExternalMapper;
import com.yixun.qfbao.model.ReportExternal;
import com.yixun.qfbao.model.dto.ReportExternalDto;
import com.yixun.qfbao.service.ReportExternalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Calendar;
import java.util.List;


/**
 * [文件名称]<br>
 * ReportExternalServiceImpl.java<br>
 * <br>
 * [文件描述]<br>
 * 报备关联表 service interface impl<br>
 * <br>
 * [修改记录]<br>
 * 2018-05-26 17:12:37 创建 陶俊代码生成器<br>
 * 
 * @author 陶俊代码生成器
 * @version 1.00
 */
@Service("reportExternalService")
public class ReportExternalServiceImpl implements ReportExternalService {
	
	@Autowired
	private ReportExternalMapper mapper;
	
	/**
	 * @param entity 搜索条件
	 * @param begin 分页开始行数[不包含]
	 * @param end 分页结束行数[包含]
	 * @return 分页记录
	 */
	@Transactional(readOnly = true)
	public Page<ReportExternal> getPageModel(ReportExternalDto entity,int begin,int end){
		Integer total = mapper.count(entity);
		List<ReportExternal> rows = mapper.list(entity,begin,end);
	    Page<ReportExternal> msr = new Page<ReportExternal>(total, rows);
		return msr;
	}

	/**
	 * 查询列表
	 * @param entity 搜索条件
	 * @return 分页记录
	 */
	public List<ReportExternal> selectListByDto(ReportExternalDto entity){
		return mapper.selectListByDto(entity);
	}
	
	/**
	 * 查询单个
	 * @param entity 搜索条件
	 * @return 分页记录
	 */
	public ReportExternal selectByDto(ReportExternalDto entity){
		return mapper.selectByDto(entity);
	}
	
	/**
	 * @param entity 搜索条件
	 * @return 分页记录
	 */
	public ReportExternal selectById(Long id){
		if(id!=null){
			return mapper.selectById(id);
		}
		return null;
	}
	/**
	 * @param entity 新增记录的详细信息
	 * @return 新增行数
	 */
	public ReportExternalDto create(ReportExternalDto entity) {
		entity.setCreateTime(Calendar.getInstance().getTime());
		mapper.add(entity);
		return entity;
	}

	/**
	 * @param entity 更新记录的详细信息
	 * @return 更新行数
	 */
	public int update(ReportExternalDto entity) {
		entity.setUpdateTime(Calendar.getInstance().getTime());
		return mapper.edit(entity);
	}
    
	/**
	 * @param entity 待删除的记录信息
	 * @return 删除行数
	 */
	public int destroy(ReportExternalDto entity) {
		return mapper.del(entity);
	}
	
	/**
	 * @param entity 新增或更新
	 * @return 新增行数
	 */
	public int saveOrUpdate(ReportExternalDto entity) {
		if(entity!=null&&entity.getId()!=null){
			return update(entity);
		}else{
			create(entity);
			return 1;
		}
	}
	
	/**
	 * @param entity 根据pojo搜索如果主键为空则返回它本身
	 * @return 一行记录或本身
	 */
	@Override
	public ReportExternal selectBy(ReportExternal entity) {
		if(entity!=null&&entity.getId()!=null){
			return mapper.selectById(entity.getId());
		}
		return entity;
	}

	@Override
	public ReportExternalDto getReportExternal(String reportUuid, String sysId) {
		ReportExternal reportExternal=mapper.getReportExternal(reportUuid, sysId);
		ReportExternalDto reportExternalDto=new ReportExternalDto();
		reportExternalDto.setId(reportExternal.getId());
		reportExternalDto.setIsDeleted(reportExternal.getIsDeleted());
		reportExternalDto.setPremiseId(reportExternal.getPremiseId());
		reportExternalDto.setPremisesUuid(reportExternal.getPremisesUuid());
		reportExternalDto.setReportId(reportExternal.getReportId());
		reportExternalDto.setReportUuid(reportExternal.getReportUuid());
		reportExternalDto.setSysId(reportExternal.getSysId());
		reportExternalDto.setUpdateTime(reportExternal.getUpdateTime());
		return reportExternalDto;
	}
}
